/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication13;

import java.io.File;


/**
 *
 * @author Irina
 */
public class Tree implements ICommandExecutor {
    
    private static ICommandExecutor instance;
    
    @Override
    public void execute(String str)
    {
        String[] strOut=str.split(" ");
       if (strOut.length==1)
        { 
            System.out.println("Не был введен адрес. Повторите попытку.");
        }
        else
       {    String NameFile=strOut[1];
            
            File fl=new File(NameFile);
            if (!fl.exists()) 
            {
                System.out.println("Данный файл не существует");
            }
            else
            {
            String gets="";
            private_TreeDirectory(fl,gets);
            System.out.println();
            }
        }
    }
    private static void private_TreeDirectory(File fl,String gets)
    {
        File [] files=fl.listFiles();
        for(File elem:files)
        {
            if(elem.isDirectory())
            {
                System.out.println(gets+"[+]"+elem.getName());
                gets+="   ";
                private_TreeDirectory(elem,gets);
                gets=gets.substring(3);
            }
            else
            {
                System.out.println(gets+elem.getName());
            }
        }  
    }

    public static ICommandExecutor getInstance()
    {
         if(instance==null)
        {
            instance=new Tree();
        }
        return instance;   
    }
}
